/*
 * KKAudioManager.h
 *
 *  Created on: 2013-9-15
 *      Author: wanghua
 */

#ifndef KKAUDIOMANAGER_H_
#define KKAUDIOMANAGER_H_

#include "kaka_common.h"

#include "KKCallback.h"
#include "KKAudioPlayer.h"

using namespace std;

USING_NS_CC;

typedef KKDictionary<string, KKAudioPlayer*> KKAudioPlayerCache;

class KKAudioManager: public CCObject {

private:

	KKAudioPlayerCache m_audioCache;

	KKAudioPlayer* m_bgMusicPlayer;

	static KKAudioManager* m_audioManager;

	inline const char* fullPathFromRelativePath(const char* path) {
		return CCFileUtils::sharedFileUtils()->fullPathFromRelativeFile(
				"xxxxxxxxxxxxx", path);
	}
public:
	KKAudioManager();
	virtual ~KKAudioManager();

	static KKAudioManager* sharedAudioManager() {
		if (!m_audioManager) {
			m_audioManager = new KKAudioManager();
		}

		return m_audioManager;
	}

	void init();

	void update(float time);

	void destory();

	KKAudioPlayer* load(const char* soundPath);

	bool play(const char* soundPath, int loop, KKCallback* endCallback = NULL);

	bool stop(const char* soundPath, bool cleanup = false);

	bool pause(const char* soundPath);

	bool resume(const char* soundPath);

	float getDuration(const char* soundPath);

	float getVolume(const char* soundPath);

	bool setVolume(const char* soundPath, float volume);

	void stopAll();

	void pauseAll();

	void resumeAll();

	void loadBackgroudMusic(const char* soundPath);
	void playBackgroudMusic(const char* soundPath, int loop);
	void stopBackgroudMusic();
	void pauseBackgroudMusic();
	void resumeBackgroudMusic();
	void setBackgroundVolume(float volume);

	void playEffect(const char* soundEffect);

	void playClickEffect();

	KKAudioPlayer* playSounds(const char* soundPath, ...);

};

#endif /* KKAUDIOMANAGER_H_ */
